package interfaceDEMO;


import interfaceDEMO.Utils.InterfacePropertoes;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import top.jfunc.json.impl.JSONObject;

import java.io.IOException;


/**
 * @author wq
 * @since 2022-06-21 17:25
 */

public class Manager {

    public static String mobileSearch(JSONObject jsonObject) throws IOException {
        //HttpPost
        HttpPost post = new HttpPost(InterfacePropertoes.managersearchurl);
        //
        post.setHeader("token",InterfacePropertoes.token);
        //jsonObject转成字符串.目的是用stringEntity转成Entity格式
        String string = jsonObject.toString();
        //string转成Entity
        StringEntity stringEntity = new StringEntity(string);
        //post设置Entity
        post.setEntity(stringEntity);
        //post.setEntity(new StringEntity(jsonObject.toString()));
        //创建 CloseableHttpClient 对象 用于发送请求
        CloseableHttpClient httpClient = HttpClients.createDefault();
        //CloseableHttpClient 对象的执行发放发送post请求,并保持数据
        CloseableHttpResponse response = httpClient.execute(post);
        //用到一个工具类EntityUtils转为String方便rutun
        String string1 = EntityUtils.toString(response.getEntity());
        return string1;
    }
}
